package com.huchao.www.Listener;

import com.huchao.www.job.*;
import com.huchao.www.utils.SchedulerUtil;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.stereotype.Component;

/**
 * @Description: SpringBoot监听器
 * @BelongsProject: background-management-v10
 * @BelongsPackage: com.huchao.www.Listener
 * @Author: 亖思
 * @CreateTime: 2023/3/21 22:19
 * @Version: 1.0
 */
@Component
public class StartAppListener implements ApplicationListener<ContextRefreshedEvent> {
    @Autowired
    private Scheduler scheduler;

    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        //每5秒
        SchedulerUtil.startScheduler(
                scheduler,
                TriggerKey.triggerKey("secondTrigger", "secondTrigger-group"),
                "secondJob",
                "secondJob-group",
                "0/5 * * * * ?",
                SecondJob.class
        );

        //每2分钟
        SchedulerUtil.startScheduler(
                scheduler,
                TriggerKey.triggerKey("minuteTrigger", "minuteTrigger-group"),
                "minuteJob",
                "minuteJob-group",
                "0 0/2 * * * ?",
                MinuteJob.class
        );

        //每1小时
        SchedulerUtil.startScheduler(
                scheduler,
                TriggerKey.triggerKey("hourTrigger", "hourTrigger-group"),
                "hourJob",
                "hourJob-group",
                "0 0 0/1 * * ?",
                HourJob.class
        );

        //每天10点
        SchedulerUtil.startScheduler(
                scheduler,
                TriggerKey.triggerKey("timeTrigger", "timeTrigger-group"),
                "timerJob",
                "timerJob-group",
                "0 0 10 * * ?",
                TimeJob.class
        );

        //每个月的1日的凌晨1点清除不用的登录记录
        SchedulerUtil.startScheduler(
                scheduler,
                TriggerKey.triggerKey("logTrigger", "logTrigger-group"),
                "logJob",
                "logJob-group",
                "0 0 1 1 1/1 ? *",
                UpdateLogJob.class
        );
    }
}
